﻿using System.Configuration.Install;
using System.Reflection;

namespace HNMS.SuperServer
{
    public static class SelfInstaller
    {
        private static readonly string ExePath = Assembly.GetExecutingAssembly().Location;

        /// <summary>
        ///     安装到服务
        /// </summary>
        /// <returns>
        ///     A bool value...
        /// </returns>
        public static bool InstallMe()
        {
            try
            {
                ManagedInstallerClass.InstallHelper(new[] { ExePath });
            }
            catch
            {
                return false;
            }
            return true;
        }

        /// <summary>
        ///     从服务中卸载
        /// </summary>
        /// <returns>
        ///     A bool value...
        /// </returns>
        public static bool UninstallMe()
        {
            try
            {
                ManagedInstallerClass.InstallHelper(new[] { "/u", ExePath });
            }
            catch
            {
                return false;
            }
            return true;
        }
    }
}
